//
//  DailyDietDetailView.m
//  SHHCPhone
//
//  Created by gfsh on 14-6-21.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "DailyDietDetailView.h"
#import "DailyDietDetailCell.h"

@implementation DailyDietDetailView
{
    UIScrollView *mainScroll;
    UIView *vLine;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        self.backgroundColor = [UIColor clearColor];
        
        mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        [mainScroll setBackgroundColor:[UIColor clearColor]];
        [mainScroll setShowsHorizontalScrollIndicator:NO];
        [mainScroll setShowsVerticalScrollIndicator:NO];
        [mainScroll setBounces:NO];
        [self addSubview:mainScroll];
        
        _dietIV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 165)];
        _dietIV.backgroundColor = NORMAL_IMAGE_BGCOLOR;//[UIColor lightGrayColor];
        [mainScroll addSubview:_dietIV];
        
        UIView *hLine = [[UIView alloc]initWithFrame:CGRectMake(0, _dietIV.frame.origin.y+_dietIV.frame.size.height, self.frame.size.width, 1)];
        hLine.backgroundColor = GET_COLOR(@"ebebeb");
        [mainScroll addSubview:hLine];
        
        vLine = [[UIView alloc]initWithFrame:CGRectMake(18, hLine.frame.origin.y+hLine.frame.size.height, 2, self.frame.size.height-(hLine.frame.origin.y+hLine.frame.size.height))];
        vLine.backgroundColor = GET_COLOR(@"f6f6f6");
        [mainScroll addSubview:vLine];
        

    }
    return self;
}

- (void)setCells:(NSArray *)cells
{
    CGFloat height = 166.f;
    for (DailyDietDetailCell *dddc in cells) {
        dddc.frame = CGRectMake(13-1, height, dddc.frame.size.width, dddc.frame.size.height);
        dddc.contentLab.frame = CGRectMake(dddc.contentLab.frame.origin.x, dddc.contentLab.frame.origin.y, dddc.titleLab.frame.size.width, dddc.frame.size.height-48);
        [mainScroll addSubview:dddc];
        height = 10+dddc.frame.origin.y+dddc.frame.size.height;
    }
    DailyDietDetailCell *dddc = [cells lastObject];
    mainScroll.contentSize = CGSizeMake(self.frame.size.width, dddc.frame.origin.y+dddc.frame.size.height+10);
    CGFloat vLineHeight = mainScroll.contentSize.height-156;
    vLine.frame = CGRectMake(vLine.frame.origin.x, vLine.frame.origin.y, vLine.frame.size.width, vLineHeight>=self.frame.size.height-156?vLineHeight:self.frame.size.height-156);
}

@end
